package com.moyuwanjia.Dao;

import com.moyuwanjia.Vo.QueryVo;
import com.moyuwanjia.domain.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author 摸鱼丸加~
 * @create 2022-03-30 21:16
 */
@CacheNamespace(blocking = true) //以注解的方式开启二级缓存
public interface IUserDao {
    /**
     * 查询所有
     * @return
     */
    List<User> findAll();    /**
     * 查询所有（注解方式）
     * @return
     */
    @Select("select * from user")
    List<User> findAll02();

    /**
     * 查询用户的总记录数
     * @return
     */
    int  FindTotal();
    /**
     * 测试OGNL表达式
     * @return
     */
    List<User> FindTotal1(QueryVo queryVo);

    /**
     * 使用注解查询
     * @return
     * Results 映射数据库对应字段结果集，与<resultMap></resultMap>功能一致,也可以被其他@ResultMap引用
     */
    @Select(value = "select * from user")
    @Results(id = "annotation_FindAllMap", value = {
            @Result(id=true,column = "username",property = "username"),
            @Result(id=true,column = "birthday",property = "birthday"),
            @Result(id=true,column = "sex",property = "sex"),
            @Result(id=true,column = "address",property = "address")
    })
    List<User> annotation_FindAll();
    /**
     * 使用注解查询
     * @return
     * ResultMap 引用映射结果集
     */
    @Select(value = "select * from user where id = #{id}")
    @ResultMap(value = {"annotation_FindAllMap"})
    User annotation_FindOne(Integer id);
    /**
     * 使用注解保存
     * @return
     */
    @Insert(value = "insert into user(username,address,sex,birthday) value(#{username},#{address},#{sex},#{birthday})")
    Integer annotation_Save(User user);
    /**
     * 使用注解更新
     * @return
     */
    @Update(value = "Update user set username = #{username} where id = #{id}")
    Integer annotation_Update(User user);
    /**
     * 使用注解删除
     * @return
     */
    @Update(value = "Delete from user where id = #{id}")
    Integer annotation_Delete(Integer id);

}
